var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
console.log(orderDetail.orderExt.platform)
if (orderDetail.orderExt.platform==10){
    $("#getGoodsType2").hide();
}else{
    $("#getGoodsType2").show();
}

window.parent.isIngReturn = false;
//初始化带入参数
$('#getGoodsAddress').html(orderDetail.orderExt.receiver_province_name+' '+orderDetail.orderExt.receiver_city_name+' '+orderDetail.orderExt.receiver_area_name+' '+orderDetail.orderExt.receiver_town_name+''+orderDetail.orderExt.receiver_detail_address);
$('#received_name').val(orderDetail.orderExt.received_name);
$('#received_telephone').val(orderDetail.orderExt.received_phone);
/*设置各种金额*/
var Return_goods = 0;//退货商品金额
var Share_freight=0 //退货商品分摊运费
var Share_coupon=0//分摊优惠(进位)
/*表格渲染*/
var dataSource = new Array();
//table的数据源
var table;   //table对象
var rejectSomeArray = {};//拒收列表对象
dataSource = [];

/*设置是否退运费*/
var isSetReturnFreight = 0; // 0-不退运费；1-退运费
function setReturnFreight(flag) {
    var service_fee = $('#service_fee').val()
    var freight = $('#freight').val()
    var Return_goods = $("#Return_goods").text()
    var Share_coupon = $("#Share_coupon").text() //分摊优惠
    var return_freight = 0; // 退运费（订单运费）

    if (flag == 1) {
        return_freight = $("#Share_freight").html();
        $("#return_freight").html(return_freight)
        isSetReturnFreight = 1;
    } else {
        $("#return_freight").html(return_freight)
        isSetReturnFreight = 0;
    }
    var refund_amount_final = Number(Return_goods) - Number(service_fee) - Number(freight) - Number(Share_coupon) + Number(return_freight);
    $('#refund_amount_final').html((refund_amount_final).toFixed(2))
}

orderList(orderDetail)
function orderList(data) {
    console.log(data)
    dataSource.splice(0, dataSource.length);//清空数组
    $.each(data.listOrderItems, function (i, field) {
        var rowData = new Array();
        rowData.push(field.product_pic);
        rowData.push(field.warehouse_id);
        rowData.push(field.buyyer_count);
        rowData.push(field.delivery_count);
        rowData.push(field.can_returned_count);
        rowData.push(field.sku_code);
        rowData.push(field.product_name);
        rowData.push(field.sku_info);
        rowData.push(field.unit_name);
        rowData.push(field.sku_id);//id
        rowData.push(field.sale_price);//单价
        rowData.push(field.fare);//运费
        rowData.push(field.coupon_value);//优惠金额
        rowData.push(field.spu_id);//spu_id
        dataSource.push(rowData);
    });
    initDataTable(dataSource);
       console.log(dataSource);
    function initDataTable(dataSource) {
        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "autoWidth": false,
            "ordering": true,
            "searching": true,
            "paging": true,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": false,
            "bLengthChange": true,
            "aLengthMenu": [5, 10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row) {
                        var val = '<div class="coenboer" data-buyyerCount="'+row[2]+'" data-fare="'+row[11]+'" data-align="'+row[10]+'" onclick="goToGoodsDetail('+row[13]+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+row[0]+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+ row[5] +'</div><div>'+ row[6] +'</div><div>'+ row[7] +'</div></div></div>';
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row) {
                        if (row[1] == 1) {
							var whereHouse = "北京仓";
						}
						var val = '<span>' + whereHouse + '</span>';
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span>'+row[2]+ ''+row[8]+'</span>';
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span>'+row[3]+ ''+row[8]+'</span>';
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span>'+row[4]+ ''+row[8]+'</span>';
                        return val;
                    },
                    "targets": 4
                },
               /* {
                    "render": function (data, type, row) {
                        var val = '<span oninput="creatArray(this,\'all\')">'+row[4]+ ''+row[8]+'</span>';
                        return val;
                    },
                    "targets": 5
                },*/
               /* {
                    "render": function (data, type, row) {/!*
                        var val = '<span><input type="text" readonly="readonly" class="input-text mr-5" onclick="creatArray(this,\'all\')" value="'+row[4]+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[2]+'</span></span>'+ row[8];
                        return val;*!/
                        var val = '<span><input type="text" readonly="readonly" class="input-text mr-5" onclick="creatArray(this,\'all\')" value="'+row[4]+'" style="width: 100px" placeholder="" id="countInp" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[2]+'</span></span>'+ row[8];
                        return val;
                    },
                    "targets": 5
                }*/
                {
                    "render": function (data, type, row) {
                        if(row[4] == 0){
                            var canReturnCount = "";
                        }else {
                            var canReturnCount = row[4];
                        }

                        var val = '<span><input type="text" readonly="readonly" class="input-text mr-5 countInp" onclick="creatArray(this,\'all\')" value="'+canReturnCount+'" style="width: 100px" placeholder="" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[2]+'</span></span>'+ row[8];
                        return val;
                    },
                    "targets": 5
                }
            ]
        });
    };

}

function returnAll() {
    /*表格渲染*/
    var dataSource = new Array();
//table的数据源
    dataSource = [];
    orderList(orderDetail)
    /*function orderList(data) {
        console.log(data)
        dataSource.splice(0, dataSource.length);//清空数组
        $.each(data.listOrderItems, function (i, field) {
            var rowData = new Array();
            rowData.push(field.product_pic);
            rowData.push(field.warehouse_id);
            rowData.push(field.buyyer_count);
            rowData.push(field.delivery_count);
            rowData.push(field.can_returned_count);
            rowData.push(field.sku_code);
            rowData.push(field.product_name);
            rowData.push(field.sku_info);
            rowData.push(field.unit_name);
            rowData.push(field.sku_id);//id
            rowData.push(field.sale_price);//单价
            rowData.push(field.fare);//运费
            rowData.push(field.coupon_value);//优惠金额
            rowData.push(field.spu_id);//spu_id
            dataSource.push(rowData);
        });
        initDataTable(dataSource);
		console.log(dataSource)
        function initDataTable(dataSource) {
            var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
            // dttable.fnClearTable(); //清空一下table
            dttable.fnDestroy(); //还原初始化了的datatable
            $("#datatable").DataTable({
                "autoWidth": false,
                "ordering": true,
                "searching": true,
                "paging": true,
                "retrieve": true,
                "destroy": true,
                "bAutoWidth": false,
                "bLengthChange": true,
                "aLengthMenu": [5, 10, 25, 50],
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='./loading.gif' />"
                },
                data: dataSource,
                columnDefs: [
                    {
                        "visible": true,
                        "targets": 0
                    },
                    {
                        "render": function (data, type, row) {
                            var val = '<div class="conlehtml" onclick="goToGoodsDetail('+row[13]+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+row[0]+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+ row[5] +'</div><div>'+ row[6] +'</div><div>'+ row[7] +'</div></div></div>';
                            return val;
                        },
                        "targets": 0
                    },
                    {
                        "render": function (data, type, row) {
                            if (row[1] == 1) {
								var whereHouse = "北京仓";
							}
							var val = '<span>' + whereHouse + '</span>';
                            return val;
                        },
                        "targets": 1
                    },
                    {
                        "render": function (data, type, row) {
                            var val = '<span>'+row[2]+ ''+row[8]+'</span>';
                            return val;
                        },
                        "targets": 2
                    },
                    {
                        "render": function (data, type, row) {
                            var val = '<span>'+row[3]+ ''+row[8]+'</span>';
                            return val;
                        },
                        "targets": 3
                    },
                    {
                        "render": function (data, type, row) {
                            var val = '<span>'+row[4]+ ''+row[8]+'</span>';
                            return val;
                        },
                        "targets": 4
                    },
                   /!* {
                        "render": function (data, type, row) {
                            if(row[4] == 0){
                                var canReturnCount = "";
                            }else {
                                var canReturnCount = row[4];
                            }
                            var val = '<span><input type="text" class="input-text mr-5" oninput="creatArray(this,\'all\')" value="'+canReturnCount+'" style="width: 100px" placeholder="" id="countInp" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[2]+'</span></span>'+ row[8];
                            return val;
                        },
                        "targets": 5
                    }*!/
                ]
            });
        };
    }*/

    for(var i = 0; i < orderDetail.listOrderItems.length; i++) {
        if(orderDetail.listOrderItems[i].can_returned_count != 0){
            rejectSomeArray[orderDetail.listOrderItems[i].sku_id] = {
                sku_id: orderDetail.listOrderItems[i].sku_id,
                sale_price: orderDetail.listOrderItems[i].sale_price,//当前单价
                return_count: orderDetail.listOrderItems[i].can_returned_count,
                fare:orderDetail.listOrderItems[i].fare,//当前运费
                coupon_value:orderDetail.listOrderItems[i].coupon_value,//当前优惠价格
                library:orderDetail.listOrderItems[i].delivery_count//当前出库数量
            }
        }
    }

    var service_fee=$('#service_fee').val('')
    var freight=$('#freight').val('')
    $('#refund_amount_final').html('0')
    Share_freight=0
    Share_coupon=0
    Return_goods=0
    var Return_goodsCS=$("#Return_goods").text();
    if(Return_goodsCS==Return_goods.toFixed(2)){
        layer.msg('已是全部退货状态', {icon: 5,time:1000});
        Share_freight=0
        Share_coupon=0
        Return_goods=0
        return false
    }
    for(var key in rejectSomeArray){
        // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
        //禁止多次点击全部退货
        Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
        Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
    }
    console.log(rejectSomeArray)
    $("#Return_goods").html((Return_goods).toFixed(2))
    $("#Share_freight").html((Share_freight).toFixed(2))
    $("#Share_coupon").html((Share_coupon).toFixed(2))

}
// 退货数量
function creatArray(val,someOrAll){
   // var Return_goods = 0;//退货商品金额
   // var Share_freight=0 //退货商品分摊运费
   // var Share_coupon=0//分摊优惠(进位)
	var numbers = $(val).parent().parent().prev().children().text()
	console.log(numbers)
    var number = numbers.replace(/[^0-9]/ig,"")
	console.log(number)
	// 验证输入的退货数量
	 if (checkInput(number, val) == false) {
	        return;
	    }
    if(val.value != "" || someOrAll == "some"){
        // 判断退货数量是否超出实际可退数量
        $.each(orderDetail.listOrderItems, function (i, field) {
            // if(val.value > field.can_returned_count){
            //     // layer.msg('退货数量不能超出可退数量', {icon: 5,time:1000});
            //     // val.value = '';
            // }
        });
        var return_countdq=val.value
        if(val.value==''){
            var return_countdq=0
        }
        rejectSomeArray[val.nextElementSibling.innerHTML] = {
            sku_id: val.nextElementSibling.innerHTML,//当前skuid
            sale_price: val.nextElementSibling.nextElementSibling.innerHTML,//当前单价
            return_count:return_countdq,//当前输入退货数量
            fare:val.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前运费
            coupon_value:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前优惠价格
            library:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前购买数量
        }
        var service_fee=$('#service_fee').val('')
        var freight=$('#freight').val('')
        $('#refund_amount_final').html('0')
        for(var key in rejectSomeArray){
            // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
            Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
            Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
        }
        console.log(rejectSomeArray)
        console.log(rejectSomeArray[key].sale_price)
        //用于全部退换的
        if(Return_goods==0){
            $("#Return_goods").html(Return_goods)
        }else{
            $("#Return_goods").html((Return_goods).toFixed(2))
        }
        $("#Share_freight").html((Share_freight).toFixed(2))
        $("#Share_coupon").html((Share_coupon).toFixed(2))
    }else if(val.value != "" || someOrAll == "all"){
        rejectSomeArray[val.nextElementSibling.innerHTML].return_count = val.value;
        // var service_fee=$('#service_fee').val('')
        // var freight=$('#freight').val('')
        var return_countdq=val.value
        if(val.value==''){
            var return_countdq=0
        }
        rejectSomeArray[val.nextElementSibling.innerHTML] = {
            sku_id: val.nextElementSibling.innerHTML,//当前skuid
            sale_price: val.nextElementSibling.nextElementSibling.innerHTML,//当前单价
            return_count:return_countdq,//当前输入退货数量
            fare:val.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前运费
            coupon_value:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前优惠价格
            library:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前购买数量
        }
        var service_fee=$('#service_fee').val('')
        var freight=$('#freight').val('')
        $('#refund_amount_final').html('0')
        for(var key in rejectSomeArray){
            // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
            Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
            Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
        }
        // console.log(rejectSomeArray)
        if(Return_goods==0){
            $("#Return_goods").html(Return_goods)
        }else{
            $("#Return_goods").html((Return_goods).toFixed(2))
        }
        $("#Share_freight").html((Share_freight).toFixed(2))
        $("#Share_coupon").html((Share_coupon).toFixed(2))

    }

    // 退运费金额
    if(isSetReturnFreight){
        $("#return_freight").html($("#Share_freight").html())
    }

}
//服务费
function service(val) {
    var service_fee=$('#service_fee').val()
    var freight=$('#freight').val()
    var Return_goods= $("#Return_goods").text()
    var Share_freight= $("#Share_freight").text()
    var Share_coupon=$("#Share_coupon").text() //分摊优惠
    var return_freight = $("#return_freight").text(); // 退运费（订单运费）
    var total =(Number(Return_goods)+Number(Share_freight)-Number(Share_coupon))*0.15 //服务费
    var totals =(Number(Return_goods)-Number(Share_coupon))//运费
    console.log(total)
        if(val==1){
            console.log(service_fee)
            if(service_fee > total){
                layer.msg('输入的服务费大于 退货商品金额+现分摊运费*15%', {icon: 5,time:1000});
                $('#service_fee').val('')
                $('#refund_amount_final').text('0.00')
            }else{
                var refund_amount_final = Number(Return_goods)-Number(service_fee)-Number(freight)-Number(Share_coupon)+Number(return_freight);
                $('#refund_amount_final').html((refund_amount_final).toFixed(2))
            }
        }else{
            console.log(freight)
            if(Number(freight)+Number(service_fee) > totals){
                layer.msg('输入的服务费+运费不能大于退货商品实际支付金额', {icon: 5,time:1000});
                $('#freight').val('')
            }else{
                var refund_amount_final = Number(Return_goods)-Number(service_fee)-Number(freight)-Number(Share_coupon)+Number(return_freight);
                $('#refund_amount_final').html((refund_amount_final).toFixed(2))
            }
        }
}
function checkInput(number, e) {
    var value = $(e).val();
    var reg = /^-?\d*$/;
    // 为空
    // 非数字
    if (reg.test(value) == false) {
        showErrorMsg(e, "格式错误，请重新输入");
        $(e).val(reg.match(value));
        return;
    }
    value = parseInt(value);
    number = parseInt(number);
    // 大于购买数量
    if (value > number) {
        showErrorMsg(e, "退货数量不能大于可退货数量！");
        if(value==0){
            $(e).val(number);// 默认数量
        }
        // 为0或者负数
    }
    if (value == 0 || value < 0) {
        showErrorMsg(e, "退货数量至少为1！");
    }else {
        // $(e).val(number);// 默认数量
        return true;
    }
    return false;
}
function showErrorMsg(e, msg) {
    // 清空非法数据
    $(e).val("");
    $.Huimodalalert(msg, 2000);
}
var originAddress = true;//有没有修改地址 true为原始地址，false为修改后的地址
var isIng = false;
function returnSome() {
    if(isIng){
        layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIng = true;
    /*最终退款总金额*/
   console.log(rejectSomeArray)
//  var refund_amount_final = 0;
    var listOrderRefundItems = [];
    for(var key in rejectSomeArray){
        if(rejectSomeArray[key].return_count!=""){
            listOrderRefundItems.push(rejectSomeArray[key]);
        }
//      refund_amount_final += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
    }
    
    for(var i=0;i<listOrderRefundItems.length;i++){
    	delete listOrderRefundItems[i].sale_price
        if(listOrderRefundItems[i].return_count == ""){
    	    listOrderRefundItems.splice(i,1);
        }
    }
    console.log(listOrderRefundItems)
    if($("#getGoodsType").val() == 10){
        if(originAddress == true){
            var queryData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                return_reason: $("#returnReason").val(),//退货原因
                return_desc: $("#returnRemark").val(),//退货说明
                take_goods_type: $("#getGoodsType").val(), //取货方式
                goods_place: $("#goods_place").val(),
                received_name: $("#received_name").val(),
                received_telephone: $("#received_telephone").val(),
                province: orderDetail.orderExt.receiver_province,
                city: orderDetail.orderExt.receiver_city,
                area: orderDetail.orderExt.receiver_area,
                town: orderDetail.orderExt.receiver_town,
                province_name:  orderDetail.orderExt.receiver_province_name,
                city_name:  orderDetail.orderExt.receiver_city_name,
                area_name:  orderDetail.orderExt.receiver_area_name,
                town_name:  orderDetail.orderExt.receiver_town_name,
                detail_address: orderDetail.orderExt.receiver_detail_address,
                service_fee: $("#service_fee").val(),
                shipping_fee: $("#freight").val(),
                return_shipping_flag: isSetReturnFreight,
                refund_amount_final: $("#refund_amount_final").html(),
                refund_desc: $("#returnMoneyRemark").val(),
                cancel_role: 20,
                operate_userid: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                operate_username: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                rejectList: listOrderRefundItems,
                proofList: proofList
            })
        }else {
            var queryData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                return_reason: $("#returnReason").val(),//退货原因
                return_desc: $("#returnRemark").val(),//退货说明
                take_goods_type: $("#getGoodsType").val(), //取货方式
                goods_place: $("#goods_place").val(),
                received_name: $("#received_name").val(),
                received_telephone: $("#received_telephone").val(),
                province: $("#pin_list1").val(),
                city: $("#pin_list2").val(),
                area: $("#pin_list3").val(),
                town: $("#pin_list4").val(),
                province_name:  $("#pin_list1").find("option:selected").html(),
                city_name:  $("#pin_list2").find("option:selected").html(),
                area_name:  $("#pin_list3").find("option:selected").html(),
                town_name:  $("#pin_list4").find("option:selected").html(),
                detail_address: $("#detailAddress").val(),
                service_fee: $("#service_fee").val(),
                shipping_fee: $("#freight").val(),
                return_shipping_flag: isSetReturnFreight,
                refund_amount_final: $("#refund_amount_final").html(),
                refund_desc: $("#returnMoneyRemark").val(),
                cancel_role: 20,
                operate_userid: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                operate_username: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                rejectList: listOrderRefundItems,
                proofList: proofList
            })
        }
    }else {
        var queryData = JSON.stringify({
            order_id:orderDetail.orderBase.order_id,
            return_reason: $("#returnReason").val(),//退货原因
            return_desc: $("#returnRemark").val(),//退货说明
            take_goods_type: $("#getGoodsType").val(), //取货方式
            goods_place: $("#goods_place").val(),
            received_name: $("#received_name").val(),
            received_telephone: $("#received_telephone").val(),
            province: 1,
            city: 100,
            area: 646,
            province_name:  "北京市",
            city_name:  "大兴区",
            area_name:  "五六环之间",
            detail_address:"黄村镇海鑫北路9号鑫方盛北京分拨中心（退货处)",
            service_fee:$("#service_fee").val(),
            shipping_fee:$("#freight").val(),
            return_shipping_flag: isSetReturnFreight,
            refund_amount_final:$("#refund_amount_final").html(),
            refund_desc:$("#returnMoneyRemark").val(),
            cancel_role:20,
            operate_userid:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            operate_username:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
            rejectList: listOrderRefundItems,
            proofList: proofList
        })
    }
//  console.log(refund_amount_final)
    $.ajax({
//  	root.orderInter.order_apply_return
        contentType: "application/json",
        type: "POST",
        url: root.orderInter.order_rejectOrder,
        cache: false,  //禁用缓存
        dataType: "json",
        data: queryData,

        success: function (result) {
            console.log(result);
            if(result.code == "0"){
                layer.msg('修改成功', {icon: 6,time:1000});
                setTimeout( function () {
                    var index =  parent.location.reload();
                    parent.layer.close(index)
                },1000);
			}else{
                isIng = false;
				layer.msg(result.message, {icon: 5, time: 1000});
			}
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            isIng = false;
        }
    });
}
// 商家上门 客户邮寄逻辑
function discount() {
    $("#getGoodsType").change(function(event) {
        var fanx = $(this).find("option:selected");
        if(fanx.val()==10){
            // 商家上门
            var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
            $('#goods_place_box').show();
            $('#getGoodsAddress').html(orderDetail.orderExt.receiver_province_name+orderDetail.orderExt.receiver_city_name+orderDetail.orderExt.receiver_area_name+orderDetail.orderExt.receiver_detail_address);
            $('#modify').show();
            $('#getgoosType').html("取货地址：")
            $('#received_name').attr("disabled",false).val(orderDetail.orderExt.received_name);
            $('#received_telephone').attr("disabled",false).val(orderDetail.orderExt.received_phone);

            // $("#detailAddress").val(orderDetail.orderExt.receiver_detail_address)
        }else{
            // 客户邮寄
            $("#Choice_address").hide();
            $("#default_address").show()
            $('#goods_place_box').hide();
            $('#getGoodsAddress').show();
            $('#modify').hide();
            $('#getgoosType').html("邮寄地址：")
            $('#getGoodsAddress').html("北京市大兴区黄村镇海鑫北路9号鑫方盛北京分拨中心（退货处)");

            $('#received_name').attr("disabled",true).val('张自平');
            $('#received_telephone').attr("disabled",true).val('010-61269550 ');
        }
    });
}
// 点击修改地址

function modifydata(val) {
    originAddress = false;
    if(val==1){
        $("#default_address").hide()
        $("#Choice_address").show()
        $("#detailAddress").val(orderDetail.orderExt.receiver_detail_address)
        discountdata(123)
        console.log(orderDetail.orderExt.receiver_province)
        $("#pin_list1").val(orderDetail.orderExt.receiver_province);
        setTimeout( function () {
           discountdata(1)
            console.log(orderDetail.orderExt.receiver_city)
            $("#pin_list2").val(orderDetail.orderExt.receiver_city);
        },100);
        setTimeout( function () {
            discountdata(2)
            $("#pin_list3").val(orderDetail.orderExt.receiver_area);
        },200);
        setTimeout( function () {
            discountdata(3)
            $("#pin_list4").val(orderDetail.orderExt.receiver_town);
        },300);
    }else {
        $("#default_address").show()
        $("#Choice_address").hide()
    }
}
//添加地址
function discountdata (val) {
    if(val==123){
        //初始化 省
        var special=$('#pin_list1').val()
        var user_data = {
            level: '101',
            // memberId:'10258',
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="1"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#pin_list1").html(cer);
                }else{
                    var cer=""
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                    }
                    $("#pin_list1").html(cer);
                }
            }
        };
        web.doAjax(root.orderInter.order_return_address,'post',user_data, succCallBack);
    }else if(val==1){
        //市
        var special=$('#pin_list1').val()
        var user_data = {
            level: '102',
            // memberId:'10258',
            addressIdStr:special
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="1"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#pin_list2").html(cer);
                }else{
                    var cer=""
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                    }
                    $("#pin_list2").html(cer);
                    $("#pin_list2").val(orderDetail.orderExt.receiver_city);
                    //选择完省出现市 去记载 区 县
                    discountdata(2)
                    setTimeout( function () {
                        discountdata(3)
                    },100);
                }
            }
        };
        web.doAjax(root.orderInter.order_return_address,'post',user_data, succCallBack);
    }else if(val==2){
        //区
        var special=$('#pin_list2').val()
        var user_data = {
            level: '103',
            // memberId:'10258',
            addressIdStr:special
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="1"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#pin_list3").html(cer);
                }else{
                    var cer=""
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                    }
                    $("#pin_list3").html(cer);
                    $("#pin_list3").val(orderDetail.orderExt.receiver_area);
                    //选择完市出现区 去记载  县
                    discountdata(3)
                }
            }
        };
        web.doAjax(root.orderInter.order_return_address,'post',user_data, succCallBack);
    }else if(val==3){
        //县
        var special=$('#pin_list3').val()
        var user_data = {
            level: '104',
            // memberId:'10258',
            addressIdStr:special
        }
        var succCallBack = function (data, status, response) {
            if(data.errorCode=="1"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#pin_list4").html(cer);
                }else{
                    var cer=""
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                    }
                    $("#pin_list4").html(cer);
                    if(orderDetail.orderExt.receiver_town != 0){
                        $("#pin_list4").val(orderDetail.orderExt.receiver_town);
                    }
                }
            }
        };
        web.doAjax(root.orderInter.order_return_address,'post',user_data, succCallBack);
    }
}

//formdata上传图片公用方法
//触发事件
function addBtn(cen) {
    $("#filesUp").trigger('click');
}
var proofList = [];//初始化图片数组
var formData = new FormData();
// 提交上传图片
function getupfilerul(e){
    console.log(formData)
    $.ajax({
        url: root.inter.imgUpload,
        cache: false,  //禁用缓存
        type: "POST",
        // 告诉jQuery不要去处理发送的数据
        processData : false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType : false,
        data: formData,
        success: function (data) {
            if(data.errorCode!=0){
                $("#addImgs").hide();
                layer.msg("上传成功", {icon: 6, time: 1000});
                 for(var i=0;i<data.length;i++){
                     proofList.push(data[i].fullPath);
                 }
                 console.log(proofList)
            } else {
                layer.msg(data.errorInfo, {icon: 5, time: 1000});
            }
            console.log(data)
        }
    })
}
// 上传图片返现
function putDataToPage(e) {
    // console.log($("#intro").val())
    for(var i = 0; i < e.target.files.length; i++) {
        var file = e.target.files.item(i);
        if(!(/^image\/.*$/i.test(file.type))) {
            continue; //不是图片 就跳出这一次循环
        }
        //实例化FileReader API
        var freader = new FileReader();
        freader.readAsDataURL(file);
        freader.onload = function (e) {
            $(".ceshi").append("<div><img class='myImg' width='50' height='50' style='margin-left: 10px' src='"+e.target.result+"'/></div>");
        }
    }
    for(var j=0;j<$("#filesUp")[0].files.length;j++){
        formData.append('file', $("#filesUp")[0].files[j]);
    }
    console.log(formData)
    $("#addPicBtn").hide();
    $("#deletBtn").show();
    $("#addImgs").show();
}
//删除图片
function deleteFiles() {
    formData = new FormData();
    $("#addImgs").hide();//隐藏上传按钮
    $(".ceshi").empty();
    $("#addPicBtn").show();
    $("#deletBtn").hide();
    proofList = [];
    /*清空input file文件*/
    var file = document.getElementById("filesUp");
    // for IE, Opera, Safari, Chrome
    if (file.outerHTML) {
        file.outerHTML = file.outerHTML;
    } else { // FF(包括3.5)
        file.value = "";
    }
}
/*跳至商品详情*/
function goToGoodsDetail(spuId) {
    sessionStorage.setItem("spuId", spuId);
    var index = layer.open({
        type: 2,
        title: "Code详情",
        content: "../../goods/goods-sku.html"
    });
    layer.full(index);
}

function countReback(){
    var Return_goods = 0;//退货商品金额
    var Share_freight=0 //退货商品分摊运费
    var Share_coupon=0//分摊优惠(进位)

    $('.countInp').each(function(k,v){
         $(this).click();
    })
}
function lsit() {
    var zomeu=0
    var fnui=0
    for(var i=0; i<$('.shun >tr').length; i++){
        var cenl=$('.shun >tr')[i]
        var nmer=$(cenl).find('.countInp').val()
        var mert=$(cenl).find('.coenboer').attr('data-align') //商品金额
        var hebert=(+ nmer)*(+ mert)
        zomeu+=hebert
        console.log(nmer)
        var mert=$(cenl).find('.coenboer').attr('data-fare') //运费金额
        var buyyercount=$(cenl).find('.coenboer').attr('data-buyyercount') //购买数量
        var geng=Number(mert)*Number(nmer)/Number(buyyercount)
        fnui+=geng
    }

    alert(zomeu)
    alert(fnui)
}
//自动加载事件
$(function(){
    countReback();
    lsit()

})
